<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :permission="permissionList"
        :before-open="beforeOpen">
        <template slot-scope="scope" slot="menuLeft">
          <el-button type="primary"
                     size="small"
                     @click.stop="handleBatchSubmit()">提 交
          </el-button>
          <approve-button
            :approve-before="approveBefore"
            @approve="handleApprove">
          </approve-button>
          <el-button type="primary"
                     size="small"
                     @click.stop="handleExport()">导 出
          </el-button>
          <el-button type="primary"
                     size="small"
                     :hidden="true"
                     v-if="false"
                     @click.stop="handlePrint()">打 印
          </el-button>
        </template>
        <template slot="menu" slot-scope="scope">
          <el-button
            type="text"
            size="small"
            icon="el-icon-tickets"
            v-if="scope.row.checkStatus=='0'||scope.row.checkStatus=='2'"
            @click.stop="rowAllot(scope.row,scope.index)">分 配
          </el-button>
          <el-button
            type="text"
            size="small"
            icon="el-icon-edit"
            v-if="scope.row.checkStatus=='0'||scope.row.checkStatus=='3'"
            @click.stop="rowApply(scope.row,scope.index)">申 请
          </el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
  import baseCrud from '@/mixins/base-crud'
  import { startDate, endDate } from "@/const/crud/subway/swstdeliveryplantempdecompose";

  export default {
    name: 'StPlanDeliveryTempDecompose',
    mixins: [baseCrud('subway/swstdeliveryplantempdecompose')],
    data() {
      return {
        params: {
          //planType: 3 , // 配送计划
          isSend: '1' // 已下发
        },
        searchForm: {
          planStartTime: startDate,
          planEndTime: endDate
        }
      }
    },
    computed: {
      permissionList() {
        return {}
      }
    },
    methods: {
      beforeOpen(done, type){
        if(type == 'view'){
          this.tableOption.group[0].display = true
          this.tableOption.group[2].display = true
          this.tableOption.group[3].display = true
        }
        done()
      },
      // 分配
      rowAllot(row, index){
        this.tableOption.editTitle = '分 配'
        if(row.ticketNumberNow){
          this.tableOption.group[0].display = true
          this.tableOption.group[0].column.forEach(column => {
            column.disabled = true
          })
          this.tableOption.group[2].display = true
          this.tableOption.group[2].column.forEach(column => {
            column.disabled = true
          })
        }else{
          this.tableOption.group[0].display = false
          this.tableOption.group[2].display = false
        }
        this.tableOption.group[3].display = true
        this.$refs.crud.rowEdit(row, index)
      },
      // 申请
      rowApply(row, index){
        this.tableOption.editTitle = '申 请'
        this.tableOption.group[0].display = true
        this.tableOption.group[0].column.forEach(column => {
          column.disabled = false
        })
        this.tableOption.group[2].display = true
        this.tableOption.group[2].column.forEach(column => {
          column.disabled = false
        })
        this.tableOption.group[3].display = false
        row.isDecompose = '1';
        this.$refs.crud.rowEdit(row, index)
      },
      approveBefore(callback){
        var tableSelect = this.$refs.crud.tableSelect
        if(tableSelect.length == 0){
          this.$message.info('请选择要审批的记录')
        }else{
          for (const table of tableSelect) {
            if (table.checkStatus != "1") {
              this.$message.error("请选择已提交的数据");
              return false;
            }
          }
          callback()
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
